home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* This module was written by Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm Mail Control Routines */
- /* */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <string.h>
- #include <fcntl.h>
- #include <time.h>
- #include <process.h>
- #include <stdlib.h>
- #include <io.h>
-
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
- #include "vfossil.h"
-
- int unattended ()
- {
- MAILP mp;
- int bzone, bnet, bnode;
- int i, j, m, r, tmp;
- long init_timer, t, t1; /* used for the timeouts */
- int done = 1; /* if we exit with this, get
- * out of BT */
- FILE *tfile;
- char jbuf[60];
-
- un_attended = 1;
- clear_statusline ();
-
- comm_bits = BITS_8;
- parity = NO_PARITY;
- stop_bits = STOP_1;
- MDM_ENABLE (btypes[baud].rate);
-
- if (fullscreen)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- }
-
- opening_banner ();
-
- if (fullscreen)
- {
- mailer_banner ();
- }
-
- if ((tfile = fopen ("BINKLEY.BAN", "rb")) != NULL)
- {
- fread (BBSwelcome, 1, 1000, tfile);
- fclose (tfile);
- }
- else
- {
- BBSwelcome[0] = '\0';
- }
-
- /* Initialize the random number generator */
- i = (int) time (NULL);
- srand (i);
-
- status_line ("+begin, %s", xfer_id);
- set_xy ("");
- XON_DISABLE ();
-
- /* Turn off forced events */
- if (noforce)
- {
- find_event ();
- noforce = 0;
- }
- if (redo_dynam)
- {
- for (i = 0; i < num_events; i++)
- {
- e_ptrs[i]->behavior &= ~MAT_SKIP;
- }
- redo_dynam = 0;
- }
-
- /*
- * See if we should exit before initializing the modem (and therefore
- * possibly letting a call sneak through)
- */
- find_event ();
- do_ready ("Init ");
-
- /* Make sure twe have all necessary parameters and that the nodelist
- * index gets read in. If not, then we must exit right now.
- */
-
- if (!net_params || !nodefind (alias[0].Zone, boss_net, boss_node, 0)){
- status_line (":something not configured. BOSSnet? BOSSnode?"); /*PLF Mon 05-08-1989 06:53:03 */
- errl_exit (254);
- }
-
- /* Set up outbound mail */
- xmit_reset ();
-
-
- /* and remember where we left off */
- if (hist.next_net != 0)
- {
- bzone = hist.next_zone;
- bnet = hist.next_net;
- bnode = hist.next_node;
- mp = find_mail (bzone, bnet, bnode);
- if ((mp == NULL) || (mp->prev == NULL))
- {
- next_mail = NULL;
- xmit_window (mail_top);
- }
- else
- {
- next_mail = mp->prev;
- xmit_window (next_mail);
- }
- }
-
- if (!CARRIER)
- {
- mdm_init (modem_init); /* Reinitialize the modem */
- }
-
- init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
- t1 = timerset (6000); /* Set a 1 minute timer */
-
- top_of_mail:
- un_attended = 1;
- i = 0;
- m = 1;
-
- /* As long as we don't press a key */
- bad_char:
- r = 0;
- more_mail = 1;
- while (!(KEYPRESS () || ctrlc_ctr))
- {
- find_event ();
-
- /* Show that we are ready */
- if (m)
- {
- if (fullscreen)
- {
- do_ready ("Waiting");
- }
- else
- {
- status_line (" Event %d - Waiting", cur_event + 1);
- }
- init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
- t1 = timerset (6000); /* Set a 1 minute timer */
- }
-
- if (timeup (t1))
- {
- put_up_time ();
- t1 = timerset (6000); /* Set a 1 minute timer */
- }
-
- /* If we haven't gotten anything in 10 minutes, re-init the modem */
- if (timeup (init_timer))
- {
- mdm_init (modem_init);
- init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
-
- /*
- * Say that we have more mail so that things entered through other
- * side of a multi-tasker will still go out
- */
- xmit_reset ();
- more_mail = 1;
-
- screen_blank = 1;
- sb_show ();
- }
-
- m = 0;
-
- if (((cur_event >= 0) && (!(e_ptrs[cur_event]->behavior & MAT_OUTONLY)))
- || (cur_event < 0))
- {
- t = 0; /*PLF Tue 05-09-1989 11:28:48 */
- /* set up the amount of time to wait at random */
- if(cur_event >= 0) /*PLF Mon 05-08-1989 06:35:34; bug fix. stop os/2 GP fault */
- t = random_time (e_ptrs[cur_event]->wait_time);
-
- if(!t) t = random_time (5); /*PLF Tue 05-09-1989 11:02:20 */
-
- while ((!timeup (t)) && (!KEYPRESS ()) && (m == 0) && !ctrlc_ctr)
- {
- find_event ();
-
- time_release ();
-
- if (timeup (t1))
- {
- put_up_time ();
- t1 = timerset (6000); /* Set a 1 minute timer */
- }
-
- /* See if we need to handle inbound mail */
- if (m = handle_inbound_mail ())
- {
- /* If we sent out anything, make sure we reset stuff */
- xmit_sameplace ();
- }
- }
-
- /* Modified */
- /*SCB*/ if ((m) && (fullscreen))
- {
- do_ready ("Waiting");
- }
- }
-
- immed_call:
-
- find_event ();
-
- /* If we are not in an event, loop again */
- if (cur_event < 0)
- {
- time_release ();
- continue;
- }
-
- /* If we have pressed a key, get out */
- if (KEYPRESS () || ctrlc_ctr)
- break;
-
- /* See if we are supposed to do any mail */
- if (e_ptrs[cur_event]->behavior & MAT_NOOUT)
- {
- continue;
- }
-
- if (more_mail)
- {
- if (more_mail = xmit_next (&bzone, &bnet, &bnode))
- {
- /* save the next call in the list in case we exit */
- if ((next_mail == NULL) || (next_mail->next == NULL))
- {
- mp = mail_top;
- }
- else
- {
- mp = next_mail->next;
- }
- hist.next_zone = mp->zone;
- hist.next_net = mp->net;
- hist.next_node = mp->node;
-
- screen_blank = 0;
- m = do_mail (bzone, bnet, bnode, 0);
-
- r = (m == 1) ? 1 : 0;
-
- if (r) /* Did we connect? */
- {
- if (!sent_mail)
- {
- /* We connected but the transfer didn't work */
- bad_call (bzone, bnet, bnode, 1);
- }
- else
- {
- /* We got through, so delete his status file */
- bad_call (bzone, bnet, bnode, -1);
- xmit_delete ();
- }
- }
-
- else if (m == 2) /* Nothing happened */
- {
- bad_call (bzone, bnet, bnode, 2);
- }
-
- /* If we did some processing */
- if (m > 0)
- {
- /* We got inbound mail */
- if (got_arcmail || got_packet || got_mail)
- {
- receive_exit ();
- }
- }
- else if (m == -1)
- {
- status_line (":Incoming call, dial aborted");
- }
- }
- }
-
- if (!more_mail)
- {
- /* No more mail to do, was it dynamic? */
- if (e_ptrs[cur_event]->behavior & MAT_DYNAM)
- {
- screen_blank = 0;
- e_ptrs[cur_event]->behavior |= MAT_SKIP;
- status_line (":End of Dynamic Event %d", cur_event + 1);
- goto top_of_mail;
- }
- }
- }
-
- screen_blank = 0;
- sb_show ();
-
- /* Eat the character we pressed */
- if (ctrlc_ctr || !KEYPRESS ())
- {
-
- /*
- * Be serious, there had to be a key pressed or we wouldn't be here I
- * know it sounds silly, but ^C will sometimes do crap like this
- */
- status_line (":Exit requested from keyboard");
- }
- else
- {
- i = FOSSIL_CHAR ();
- if ((i & 0xff) == 0)
- {
- switch (i)
- {
- case PF1:
- case PF2:
- case PF3:
- case PF4:
- case PF5:
- case PF6:
- case PF7:
- case PF8:
- case PF9:
- case PF10:
- i = i >> 8;
- status_line (":Function key exit - errorlevel %d", (i - 0x3a) * 10);
- errl_exit ((i - 0x3a) * 10);
-
- case ALTB:
- screen_blank = 1;
- sb_show ();
- goto bad_char;
-
- case ALTC:
- tmp = hist.which_day;
- memset (&hist, 0, sizeof (HISTORY));
- hist.which_day = tmp;
- if (fullscreen)
- {
- do_today ();
- sb_show ();
- }
- goto bad_char;
-
- case ALTE:
- if (BBSreader != NULL)
- {
- vfossil_cursor (1);
- status_line (" Disabling Modem");
- mdm_init (modem_busy);
- DTR_OFF ();
- status_line (":Invoking Message Reader");
- vfossil_close ();
- b_spawn (BBSreader);
- vfossil_init ();
- if (fullscreen)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- opening_banner ();
- mailer_banner ();
- }
- status_line (":Message Reader returned to BinkleyTerm");
- xmit_reset ();
- m = 1;
- status_line (" Enabling Modem");
- DTR_ON ();
- mdm_init (modem_init);
- goto immed_call;
- }
- else
- {
- set_xy (NULL);
- status_line ("!No Message Reader to invoke");
- set_xy (NULL);
- m = 1;
- goto bad_char;
- }
-
- case ALTJ:
- goto do_esc;
-
- case ALTM:
- status_line (":Entering POLL Mode");
- /*SCB*/ if (fullscreen)
- gotoxy (0, 21);
- /*
- tmp = fullscreen;
- fullscreen = 0;
- */
- vfossil_cursor (1);
- scr_printf ("\r\nPlease enter a net/node number: ");
- scr_printf (local_CEOL);
- if (m = get_number (jbuf))
- {
- if ((m = sscanf (jbuf, "%d:%d/%d", &bzone, &bnet, &bnode)) != 3)
- {
- bzone = 0;
- if ((m = sscanf (jbuf, "%d/%d", &bnet, &bnode)) != 2)
- {
- bzone = alias[0].Zone;
- bnet = alias[0].Net;
- if ((m = sscanf (jbuf, "%d", &bnode)) == 1)
- {
- m = 3;
- }
- }
- else
- {
- m = 3;
- }
- }
- }
- if (fullscreen)
- {
- gotoxy (0, 22);
- scr_printf (local_CEOL);
- bottom_line ();
- vfossil_cursor (0);
- sb_show ();
- }
- doing_poll = 1;
- if (m >= 2 && nodefind (bzone, bnet, bnode,1))
- {
- if (!bzone)
- bzone = found_zone;
- if (fullscreen)
- {
- sb_move (filewin, 1, 2);
- sb_puts (filewin, "Currently Polling Node ");
- sb_puts (filewin, jbuf);
- }
- if ((do_mail (bzone, bnet, bnode, 1) == 1) && sent_mail)
- {
- next_mail = find_mail (bzone, bnet, bnode);
- bad_call (bzone, bnet, bnode, -1);
- xmit_delete ();
- }
- }
- doing_poll = 0;
- status_line (":Poll completed");
- if (fullscreen)
- {
- clear_filetransfer ();
- }
- DTR_ON ();
- mdm_init (modem_init);
- m = 1;
- goto bad_char;
-
- case ALTQ:
- if (cur_event != -1)
- e_ptrs[cur_event]->behavior |= MAT_SKIP;
- goto top_of_mail;
-
- case ALTR:
- for (j = 0; j < num_events; j++)
- {
- /* Don't redo forced events */
- if (!(e_ptrs[j]->behavior & MAT_FORCED))
- {
- e_ptrs[j]->last_ran = -1;
- e_ptrs[j]->behavior &= ~MAT_SKIP;
- }
- }
- goto top_of_mail;
-
- case ALTT:
- status_line (":Keyboard request to enter terminal mode");
- b_init ();
- done = 0; /* We won't exit now */
- goto mail_done;
-
- case ALTW:
- if (fullscreen)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- sb_show ();
- }
- goto bad_char;
-
- case ALTF10:
- mailer_help ();
- if (fullscreen)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- opening_banner ();
- mailer_banner ();
- }
- m = 1;
- goto bad_char;
-
- case ALTX:
- status_line (":Exit requested from keyboard");
- goto mail_done;
-
- case ALTF1:
- case ALTF2:
- case ALTF3:
- case ALTF4:
- case ALTF5:
- case ALTF6:
- case ALTF7:
- case ALTF8:
- case ALTF9:
- j = (i >> 8) - 0x68;
- if (shells[j] != NULL)
- {
- status_line (":Executing keyboard shell %d", j + 1);
- mdm_init (modem_busy);
- DTR_OFF ();
- close_up ();
- vfossil_cursor (1);
- b_spawn (shells[j]);
- come_back ();
- m = 1;
- status_line (":Returning from keyboard shell");
- scr_printf ("\033[H\033[2J");
- if (fullscreen)
- sb_dirty ();
- opening_banner ();
- mailer_banner ();
- xmit_reset ();
- DTR_ON ();
- mdm_init (modem_init);
- goto immed_call;
- }
-
- status_line ("!No keyboard shell %d", j + 1);
- goto bad_char;
-
- case PGUP:
- if (next_mail == NULL)
- {
- next_mail = mail_top;
- }
-
- if (next_mail != NULL)
- {
- for (j = 0; j < 4; j++)
- {
- if (next_mail->prev != NULL)
- next_mail = next_mail->prev;
- }
- xmit_window (next_mail);
- }
- goto bad_char;
-
- case PGDN:
- if (next_mail == NULL)
- {
- next_mail = mail_top;
- }
-
- if (next_mail != NULL)
- {
- for (j = 0; j < 4; j++)
- {
- if (next_mail->next != NULL)
- next_mail = next_mail->next;
- }
- xmit_window (next_mail);
- }
- goto bad_char;
-
- case UPAR:
- if (next_mail == NULL)
- {
- next_mail = mail_top;
- }
-
- if (next_mail != NULL)
- {
- if (next_mail->prev != NULL)
- next_mail = next_mail->prev;
- xmit_window (next_mail);
- }
- goto bad_char;
-
- case DNAR:
- if (next_mail == NULL)
- {
- next_mail = mail_top;
- }
-
- if (next_mail != NULL)
- {
- if (next_mail->next != NULL)
- next_mail = next_mail->next;
- xmit_window (next_mail);
- }
- goto bad_char;
-
- case HOME:
- next_mail = mail_top;
- xmit_window (next_mail);
- goto bad_char;
-
- case END:
- if (next_mail == NULL)
- {
- next_mail = mail_top;
- }
-
- if (next_mail != NULL)
- {
- while (next_mail->next != NULL)
- {
- next_mail = next_mail->next;
- }
- }
-
- for (j = 0; j < 3; j++)
- {
- if (next_mail->prev != NULL)
- next_mail = next_mail->prev;
- }
- xmit_window (next_mail);
- goto bad_char;
-
- default:
- status_line (" Junk character from keyboard - continuing");
- m = 1;
- goto bad_char;
- }
- }
- else
- {
- switch (i & 0xff)
- {
- case ESC: /*PLF Mon 05-08-1989 08:02:13 ; had to move code around a bit, the optimixer has having probs.*/
- do_esc:
- status_line (":Exiting to DOS");
- /*SCB*/ if (fullscreen)
- gotoxy (0, 23);
- vfossil_cursor (1);
- cputs ("Type EXIT to return to BT");
- DTR_OFF ();
- change_prompt ();
- b_spawn (NULL);
- if (fullscreen)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- opening_banner ();
- mailer_banner ();
- }
- status_line (":BinkleyTerm Reactivated");
- m = 1;
- xmit_reset ();
-
- /* and remember where we left off */
- if (hist.next_net != 0)
- {
- bzone = hist.next_zone;
- bnet = hist.next_net;
- bnode = hist.next_node;
- mp = find_mail (bzone, bnet, bnode);
- if ((mp == NULL) || (mp->prev == NULL))
- {
- next_mail = NULL;
- xmit_window (mail_top);
- }
- else
- {
- next_mail = mp->prev;
- xmit_window (next_mail);
- }
- }
-
- DTR_ON();
- goto bad_char;
- case 'C':
- case 'c':
- if( cur_event >= 0 ) /*PLF Mon 05-08-1989 11:37:12 */
- if (e_ptrs[cur_event]->behavior & MAT_NOOUT)
- {
- status_line ("!Calls not permitted during this event.");
- goto immed_call;
- }
-
- status_line (" Immediate call requested");
- m = 0;
- more_mail = 1;
- goto immed_call;
-
- case 3:
- status_line (":Exit requested from keyboard");
- goto mail_done;
-
-
- case 0x20:
- m = 1;
- goto bad_char;
-
- default:
- status_line (" Junk character from keyboard - continuing");
- m = 1;
- goto bad_char;
- }
- }
- }
-
- mail_done:
- write_sched ();
- status_line ("+end, %s", xfer_id);
- un_attended = 0;
- /*SCB*/ if (fullscreen)
- {
- gotoxy (0, 23);
- }
- XON_ENABLE ();
- return (done);
- }